//
//  SaveCell.m
//  MyTrip
//
//  Created by zhang on 15/9/1.
//  Copyright (c) 2015年 张益. All rights reserved.
//

#import "SaveCell.h"
#import "Diary.h"
#import "UIImageView+WebCache.h"

@implementation SaveCell

- (void)dealloc
{
    [_startLabel release];
    [_picImage release];
    [_titleLabel release];
    [_authorNameLabel release];
    [_authorImage release];
    [super dealloc];
}

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.authorImage = [[[UIImageView alloc] initWithFrame:CGRectMake(5 * OffWidth, 5 * OffHeight, 30 * OffWidth, 30 * OffHeight)] autorelease];
        [self.contentView addSubview:_authorImage];
        
        self.authorNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_authorImage.frame.size.width + _authorImage.frame.origin.x + 5 * OffWidth, 3 * OffHeight, 100 * OffWidth, 30 * OffHeight)];
        [self.contentView addSubview:_authorNameLabel];
        
        self.picImage = [[[UIImageView alloc] initWithFrame:CGRectMake(_authorImage.frame.size.width + _authorImage.frame.origin.x + 3 * OffWidth, _authorNameLabel.frame.size.height + _authorNameLabel.frame.origin.y, 100 * OffWidth, 70 * OffHeight)] autorelease];
        [self.contentView addSubview:_picImage];
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_picImage.frame.origin.x + 3 * OffWidth + _picImage.frame.size.width, _authorNameLabel.frame.size.height + _authorNameLabel.frame.origin.y, 375 * OffWidth - _picImage.frame.origin.x + 3 * OffWidth + _picImage.frame.size.width, 60 * OffHeight)];
        _titleLabel.numberOfLines = 2;
        [self.contentView addSubview:_titleLabel];
        
        
    }
    return self;
}


- (void)setValueWithDiary:(Diary *)diary{
    
    [_authorImage sd_setImageWithURL:[NSURL URLWithString:diary.authorImage] placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    [_picImage sd_setImageWithURL:[NSURL URLWithString:diary.pic] placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    [_authorNameLabel setText:diary.authorName];
    [_authorNameLabel setFont:[UIFont systemFontOfSize:14]];
    
    
    [_titleLabel setText:diary.title];
    [_titleLabel setFont:[UIFont systemFontOfSize:15]];
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    CGRect rect = [diary.title boundingRectWithSize:CGSizeMake(320 * OffWidth, 1000000000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    [_titleLabel setFrame:CGRectMake(_picImage.frame.origin.x + 3 + _picImage.frame.size.width, _authorNameLabel.frame.size.height + _authorNameLabel.frame.origin.y, 375 * OffWidth - _picImage.frame.origin.x - 3 * OffWidth - _picImage.frame.size.width, rect.size.height * OffHeight)];
    _titleLabel.adjustsFontSizeToFitWidth= YES;
    [_titleLabel setNumberOfLines:0];
}






- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
